/*
 * Copyright 2011 derek.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.aocore.map;

import com.aocore.d2data.AreaLevel;
import java.nio.ByteBuffer;

/**
 *
 * @author derek
 */
public class Map
{
    private AreaLevel area;
    private int orginX;
    private int orginY;
    private int width;
    private int height;
    private byte[][] map;

    public Map(AreaLevel area, ByteBuffer byteBuffer)
    {
        this.area = area;

        orginX = byteBuffer.getInt();
        orginY = byteBuffer.getInt();
        width = byteBuffer.getInt();
        height = byteBuffer.getInt();
        map = new byte[width][height];

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                map[x][y] = byteBuffer.get();
            }
        }
    }

    public void print()
    {
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                System.out.print((char)('a' + map[x][y]));
            }
            System.out.println();
        }
    }

    public AreaLevel getArea()
    {
        return area;
    }

    public int getOrginX()
    {
        return orginX;
    }

    public int getOrginY()
    {
        return orginY;
    }

    public int getWidth()
    {
        return width;
    }

    public int getHeight()
    {
        return height;
    }

    public int get(int x, int y)
    {
        return map[x][y];
    }

    public boolean isValid(int x, int y)
    {
        return (x >= orginX) && (x < orginX + width) && (y >= orginY) && (y < orginY + height);
    }
}
